//
//  ParentViewController.m
//  Qihuo
//
//  Created by ~Fighting~ on 13-10-20.
//  Copyright (c) 2013年 Vencoo. All rights reserved.
//
#import "UIButton+MyButton.h"
#import "ParentViewController.h"
#import "MyTextField.h"
@interface ParentViewController ()
{
    UIButton *departBtn;
}
@end

@implementation ParentViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
//[Appinfomation shareIstance].timeDateStr1 = @"sda";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self addBackButton];
    
    UIImage *backgroundImage = [UIImage imageNamed:@"底111"];
    UIImageView *backgroundView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, backgroundImage.size.width, 768)];
    [backgroundView setImage:backgroundImage];
    [self.view addSubview:backgroundView];
	// Do any additional setup after loading the view.
}
-(void)loadnimeiView
{
    
//    [[Appinfomation shareIstance].player initWithContentsOfURL:soundUrl error:nil];
//    player=[[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
//    [[Appinfomation shareIstance].player prepareToPlay];
}

- (void)addBackButton
{
    UIImage *image = [UIImage imageNamed:@"返回"];
    UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(60, (44-image.size.height)/2, image.size.width, image.size.height);
    [btn setBackgroundImage:image forState:UIControlStateNormal];
    [btn addTarget:self.navigationController action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* backBtn = [[UIBarButtonItem alloc]initWithCustomView:btn];
    self.navigationItem.leftBarButtonItem = backBtn;
    
}
- (void)addRightButton
{
    UIImage *image = [UIImage imageNamed:@"添加"];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setBackgroundImage:image forState:UIControlStateNormal];
    btn.frame = CGRectMake(1004 - image.size.width, (44-image.size.height)/2, image.size.width, image.size.height);
    btn.tag = 0;
    [btn addTarget:self action:@selector(add:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* backBtn = [[UIBarButtonItem alloc]initWithCustomView:btn];
    self.navigationItem.rightBarButtonItem = backBtn;
}
- (void)addUpButton
{
    
    
}
- (void)addSearch
{
    UIImage *searchImage = [UIImage imageNamed:@"搜索框"];
    UIImage *searchIcon = [UIImage imageNamed:@"搜索"];
    UIImageView *searchView = [[UIImageView alloc]initWithImage:searchImage];
    searchView.frame = CGRectMake(20 + 220 + 195, 70, searchImage.size.width, searchImage.size.height);
    searchView.userInteractionEnabled = YES;
    _seachBar = [[MyTextField alloc]initWithFrame:CGRectMake(20,0,searchImage.size.width-20-searchIcon.size.width - 20,searchImage.size.height)];
    [_seachBar setFont:[UIFont systemFontOfSize:bigCharacter]];
    [_seachBar setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];
    //    seachBar.borderStyle = 2;
    _seachBar.textColor = [UIColor whiteColor];
    _seachBar.backgroundColor = [UIColor clearColor];
    [self.view addSubview:searchView];
    [searchView  addSubview:_seachBar];    
    
    UIImageView *iconView = [[UIImageView alloc]initWithFrame:CGRectMake(searchView.frame.origin.x + searchView.frame.size.width - searchIcon.size.width - 20, searchView.frame.origin.y + 5, searchIcon.size.width, searchIcon.size.height)];
    [iconView setImage:searchIcon];
    [self.view addSubview:iconView];
    
    UIImage *buttonImage = [UIImage imageNamed:@"搜索按钮"];
    UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [searchBtn setImage:buttonImage forState:UIControlStateNormal];
    searchBtn.frame = CGRectMake(searchView.frame.origin.x + searchView.frame.size.width+5 , searchView.frame.origin.y, buttonImage.size.width, buttonImage.size.height);
    [searchBtn addTarget:self action:@selector(searchInfo:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:searchBtn];
    
}

-(void)addArray:(NSArray *)array
{
    UIImage *image = [UIImage imageNamed:@"选项按钮-底"];
    for (int i = 0; i<array.count; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [btn setBackgroundImage:image forState:UIControlStateNormal];
        btn.frame = CGRectMake((scrennWidth - image.size.width*3)/4*(i%3+1) + image.size.width * (i%3), 44+(screenHeight - 44 - image.size.height*3)/4*(i/3+1) + image.size.height * (i/3), image.size.width, image.size.height);
        [self.view addSubview:btn];
        btn.tag = i;
        [btn addFirstLine:[array objectAtIndex:i]];
        [btn addTarget:self action:@selector(clicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight );
    
}

-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}

- (BOOL)shouldAutorotate
{
    return YES; 
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
